/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */
@isTest
private class issueRecieptAndInvoiceClass_Test1 
{

    static testMethod void myUnitTest() 
    {
        // TO DO: implement unit test
        string result = null;
        List<string> resultList = null;
        
        //Account Object Record...
        Account accountObject1 = new Account();
        accountObject1.Name = 'Test Account';
        //accountObject1.LicenseNumber__c = serialObject.id;
        accountObject1.License_Application_Step__c = 'Archived';
        accountObject1.Activity__c = 'Trading - One Activity';
        accountObject1.License_Issue_Date__c = system.today().addyears(-2);
        accountObject1.Master_Account_Flag__c = true;
        accountObject1.License_Application_Type__c = 'Renewal Additional';
        accountObject1.License_Expiry_Date__c = System.Today().addYears(-1);
        accountObject1.Renew_Additional_Type__c = 'Renew With Change Location';
        
        insert accountObject1;

		Account accountObject2 = new Account();
        accountObject2.Name = 'Test Account';
        //accountObject2.LicenseNumber__c = serialObject.id;
        accountObject2.License_Application_Step__c = 'Archived';
        accountObject2.Activity__c = 'Trading - One Activity';
        accountObject2.License_Issue_Date__c = system.today();
        accountObject2.Master_Account_Flag__c = true;
        accountObject2.License_Expiry_Date__c = System.Today().addYears(1);
        accountObject2.License_Application_Type__c = 'Renewal Additional';
        accountObject2.Renew_Additional_Type__c = 'Renew With Change Location';
        insert accountObject2;
                
        
        //For Location Object Records...
        Location__c locationObject1 = new Location__c();
        locationObject1.Name = 'Test Office';
        locationObject1.Location_Type__c = 'Office';
        locationObject1.Rental_Rate__c = 18000;
        insert locationObject1;
        
        //For Location Object Records...
        Location__c locationObject2 = new Location__c();
        locationObject2.Name = 'Test Office 13545467';
        locationObject2.Location_Type__c = 'Office';
        locationObject2.Rental_Rate__c = 18000;
        insert locationObject2;
        
        //For Location Object Records...
        Location__c locationObject3 = new Location__c();
        locationObject3.Name = 'Test Office 25546546745';
        locationObject3.Location_Type__c = 'Office';
        locationObject3.Rental_Rate__c = 18000;
        insert locationObject3;
        
        //For Tenancy Object Records...
        RecordType newTenancyRecordType = [select Id,IsActive,SObjectType,DeveloperName from RecordType where DeveloperName = 'New_Tenancy_Contract' AND SObjectType = 'Tenancy_Contract__c'];
        Tenancy_Contract__c tenancyObject1 = new Tenancy_Contract__c();
        tenancyObject1.Location__c = locationObject1.id;
        tenancyObject1.RecordTypeId = newTenancyRecordType.id;
        tenancyObject1.Tenant__c = accountObject1.id;
        tenancyObject1.Tenancy_Contract_Start_Date__c = accountObject1.License_Issue_Date__c;
        tenancyObject1.Tenancy_Contract_Expiry_Date__c = date.TODAY().addyears(-1).adddays(-1);
        insert tenancyObject1;
        
        //Now For Account Locations ....
        Account_Location__c accountLocationObject1 = new Account_Location__c();
        accountLocationObject1.Account__c = accountObject1.Id;
        accountLocationObject1.Previous_Location__c = locationObject1.Id;
        accountLocationObject1.Previous_Tenancy_Contract__c = tenancyObject1.Id;
        accountLocationObject1.New_Location__c = locationObject3.id;
        insert accountLocationObject1;
        
        
        //Updating with the current Tenancy Contract Field...
        locationObject1.Current_Tenancy_Contract__c = tenancyObject1.Id;
        update locationObject1;
        
        //For Release Location Method...
        result = issueRecieptAndInvoiceClass.releaseLocationSetupMethod(accountObject1.Id, 'Renew With Change Location');
    	
    	//For Tennacy Object Update Because above method release the location and cancel the license..
    	tenancyObject1.Tenancy_Contract_Cancellation_Date__c = null;
        update tenancyObject1;
    	
    	//Updating with the current Tenancy Contract Field...
        locationObject1.Current_Tenancy_Contract__c = tenancyObject1.Id;
        update locationObject1;
    	
    	
    	//For Suspension Object Records...
        Fines__c fineObject1 = new Fines__c();
        fineObject1.Issue_Date__c = System.today();
        fineObject1.Account__c = accountObject1.id;
        fineObject1.Fine_Type__c = 'Fix Amount';
        fineObject1.Fine_Amount__c = 1000;
        fineObject1.Fines_Included__c = true;
        fineObject1.Status__c = 'Approved';
        insert fineObject1;
        
        
    	//First Creating all the fee and Service Pricebook related to the methods...
    	//For Fees Object Records....
        List<Fee__c> feeObjectList = new List<Fee__c>();
        
        Fee__c feeObject3 = new Fee__c();
        feeObject3.Name = 'Tenancy Delay Fee For Renewal';
        feeObject3.Fee_Type__c = 'Tenancy Delay Fee For Renewal';
        feeObject3.Price__c = 56;
        feeObjectList.add(feeObject3);
        
        Fee__c feeObject4 = new Fee__c();
        feeObject4.Name = 'Non Refundable';
        feeObject4.Fee_Type__c = 'Non Refundable';
        feeObject4.Price__c = 56;
        feeObjectList.add(feeObject4);
                
        Fee__c feeObject5 = new Fee__c();
        feeObject5.Name = 'Office';
        feeObject5.Fee_Type__c = 'Office';
        feeObject5.Price__c = 56;
        feeObjectList.add(feeObject5);
        
        
        Fee__c feeObject6 = new Fee__c();
        feeObject6.Name = 'License Delay Fee For Renewal';
        feeObject6.Fee_Type__c = 'License Delay Fee For Renewal';
        feeObject6.Price__c = 56;
        feeObjectList.add(feeObject6);
        
        //Now Insert the Fee Object List...
        if(feeObjectList.size() > 0)
        	insert feeObjectList;
        
        
        //For Service Pricebook...
        List<Service_Price_Book__c> serviceBookList = new List<Service_Price_Book__c>();
        List<string> serviceBookTypeList = new List<string>();
        
        serviceBookTypeList.add('Renewal');
        serviceBookTypeList.add('New License');
        serviceBookTypeList.add('Cancellation');
        serviceBookTypeList.add('Amendment');
        serviceBookTypeList.add('Renewal Additional');
        
        for(String tempString : serviceBookTypeList)
        {
        	for(integer counter = 0; counter < feeObjectList.size(); counter++ )
        	{
        		Service_Price_Book__c servicePriceBook1 = new  Service_Price_Book__c();
	            servicePriceBook1.fee__c = feeObjectList[counter].id;
	            servicePriceBook1.License_Application_Type__c  = tempString;//'New License';
	            servicePriceBook1.License_App_Category__c  = 'Trading - One Activity';
	            servicePriceBook1.isActive__c = true;
	            
	            Service_Price_Book__c servicePriceBook2 = new  Service_Price_Book__c();
	            servicePriceBook2.fee__c = feeObjectList[counter].id;
	            servicePriceBook2.License_Application_Type__c  = tempString;//'New License';
	            servicePriceBook2.License_App_Category__c  = 'Trading - Two Activity';
	            servicePriceBook2.isActive__c = true;
	            
	            Service_Price_Book__c servicePriceBook3 = new  Service_Price_Book__c();
	            servicePriceBook3.fee__c = feeObjectList[counter].id;
	            servicePriceBook3.License_Application_Type__c  = tempString;//'New License';
	            servicePriceBook3.License_App_Category__c  = 'Trading - Three Activity';
	            servicePriceBook3.isActive__c = true;
	            
        		Service_Price_Book__c servicePriceBook4 = new  Service_Price_Book__c();
	            servicePriceBook4.fee__c = feeObjectList[counter].id;
	            servicePriceBook4.License_Application_Type__c  = tempString;//'New License';
	            servicePriceBook4.Location_Type__c = 'Land';
	            servicePriceBook4.License_App_Category__c  = 'Location'; 
	            servicePriceBook4.isActive__c = true;
	            
	            Service_Price_Book__c servicePriceBook5 = new  Service_Price_Book__c();
	            servicePriceBook5.fee__c = feeObjectList[counter].id;
	            servicePriceBook5.License_Application_Type__c  = tempString;//'New License';
	            servicePriceBook5.Location_Type__c = 'Office';
	            servicePriceBook5.License_App_Category__c  = 'Location'; 
        		servicePriceBook5.isActive__c = true;
        		
        		Service_Price_Book__c servicePriceBook6 = new  Service_Price_Book__c();
	            servicePriceBook6.fee__c = feeObjectList[counter].id;
	            servicePriceBook6.License_Application_Type__c  = tempString;//'New License';
	            servicePriceBook6.Location_Type__c = 'Guarantee';
	            servicePriceBook6.License_App_Category__c  = 'Location';
	            servicePriceBook6.isActive__c = true;
	            
	            Service_Price_Book__c servicePriceBook7 = new  Service_Price_Book__c();
	            servicePriceBook7.fee__c = feeObjectList[counter].id;
	            servicePriceBook7.License_Application_Type__c  = tempString;//'New License';
	            servicePriceBook7.License_App_Category__c  = 'Trading - General Trading';
	            servicePriceBook7.isActive__c = true;
	            
	            Service_Price_Book__c servicePriceBook8 = new  Service_Price_Book__c();
	            servicePriceBook8.fee__c = feeObjectList[counter].id;
	            servicePriceBook8.License_Application_Type__c  = tempString;//'New License';
	            servicePriceBook8.License_App_Category__c  = 'Services';
	            servicePriceBook8.isActive__c = true;
        		
        		//Adding in the list...
        		serviceBookList.add(servicePriceBook1);
        		serviceBookList.add(servicePriceBook2);
        		serviceBookList.add(servicePriceBook3);
        		serviceBookList.add(servicePriceBook4);
        		serviceBookList.add(servicePriceBook5);
        		serviceBookList.add(servicePriceBook6);
        		serviceBookList.add(servicePriceBook7);
        		serviceBookList.add(servicePriceBook8);
        		
        		
        		
        	}
        
        
        }
        
        //For inserting the Service PRicebook...
        if(serviceBookList.size() > 0)
        	insert serviceBookList;
        
        
        Tenancy_Contract__c tenancyObject2 = new Tenancy_Contract__c();
        tenancyObject2.Location__c = locationObject2.id;
        tenancyObject2.RecordTypeId = newTenancyRecordType.id;
        tenancyObject2.Tenant__c = accountObject1.id;
        tenancyObject2.Tenancy_Contract_Start_Date__c = accountObject1.License_Issue_Date__c;
        tenancyObject2.Tenancy_Contract_Expiry_Date__c = date.TODAY().addyears(-1).adddays(-1);
        insert tenancyObject2;
        
        //Updating with the current Tenancy Contract Field...
        locationObject1.Current_Tenancy_Contract__c = tenancyObject1.Id;
        update locationObject1;
        
        //Creating the Account Location 2...
        Account_Location__c accountLocationObject2 = new Account_Location__c();
        accountLocationObject2.Account__c = accountObject1.Id;
        accountLocationObject2.Previous_Location__c = locationObject2.Id;
        accountLocationObject2.Previous_Tenancy_Contract__c = tenancyObject2.Id;
        accountLocationObject2.renewAddLocationFlag__c = true;
        insert accountLocationObject2;
        
        
        
        string popDate  = string.valueof(accountObject1.License_Expiry_Date__c); 
        System.debug('The Before POP Date => '+ popDate);
        popDate = string.valueOf(popDate.split('-')[2]+'/'+popDate.split('-')[1]+'/'+popDate.split('-')[0]);
        System.debug('The After POP Date => '+ popDate);
        //For Generating the Invoice For the Renewal With Additional Features (Add Location and Change Location) Methods...
    	resultList = issueRecieptAndInvoiceClass.generatingInvoiceAndLineItemForRenewalLicenseAdditionalMethod(accountObject1.Id, accountObject1.License_Application_Type__c, accountObject1.Activity__c,popDate, 'Renew With Change Location','False',null);
    	
    	
    	//For Creating the Tenancy Contract Method For Renewal Additional (Add Location & Change Location ) License...
    	resultList = issueRecieptAndInvoiceClass.creatingTenancyContractForRenewalAdditionalLicenseMethod(accountObject1.Id);
    	
    	
    	//For Confirm Renewal Button...
    	result = issueRecieptAndInvoiceClass.confirmCompanyRegistrationForRenewalLicenseMethod(accountObject1.id,'Renewal Additional', 'Renewal Amendment');
    	
    	
    	
        
    }
}